package control

import (
	"service/app/dao"
	"service/app/dto"
	"service/app/mode"
)

type PmControl struct {
	BaseContr *BaseContr
	// UserC     *UserContr
	// PermC     *PermCont
	Dao *dao.PmDao
}

var pmcontrol *PmControl

func PmInit() *PmControl {
	if pmcontrol == nil {
		pmcontrol = &PmControl{BaseContr: &BaseContr{}, Dao: dao.PmDaoInit()}
		// pmcontrol = &PmControl{BaseContr: &BaseContr{}, UserC: NewUserContr(), PermC: PermContrInit(), Dao: dao.PmInit()}
	}
	return pmcontrol
}

func (m *PmControl) PmEditC(id *dto.ReqUriIdDto, api *mode.Db_pm) error {
	return m.Dao.PmEditC(id, api)
}
func (m *PmControl) Pm_delC(id dto.ReqUriIdDto) error {
	return m.Dao.Pm_delD(id)
}
func (m *PmControl) Pmlist_pageC(pageOpt *dto.ReqPaginat) (*[]mode.Db_pm, int64, error) {
	return m.Dao.Pmlist_pageD(pageOpt)
}

func (m *PmControl) PmUrlRelRoleC(id *dto.ReqUriIdDto, pmUrlList *dto.Ipm_pmUrlList) error {
	return m.Dao.PmUrlRelRoleD(id, pmUrlList)
}

func (m *PmControl) PmSqlExitsC(param *dto.Ipm_add) (*mode.Db_pm, error) {
	return m.Dao.PmSqlExitsD(param)
}

func (m *PmControl) Pm_R_listC() (*[]mode.Db_pm, error) {
	return m.Dao.Pm_R_listD()
}

func (m *PmControl) PmAcRolesC(id *dto.ReqUriIdDto, param *dto.Ipm_roles) error {
	return m.Dao.PmAcRolesD(id, param)
}

/** 创建地址*/
func (m *PmControl) PmCreateC(ac *dto.Ipm_add) error {
	return m.Dao.PmCreateD(ac)
}

func (m *PmControl) PmAddListC(ac *dto.Ipm_addList) error {
	return m.Dao.PmAddListD(ac)
}

/** 为了方法调试所以加个TAG*/
func (m *PmControl) PmAuthC(role *[]mode.Db_roles, userName string) (*[]mode.Db_menu, error) {
	var havePerm []mode.Db_menu
	list, err := menusCont.MenuGetAll()
	// test 管理员测试
	if userName == "admin" {
		return list, nil
	}
	if err != nil {
		return nil, err
	}
	// 从用户中获取到权限列表
	// roleList, err := permCont.GetList(role)
	// if err != nil {
	// 	return nil, err
	// }
	// for _, v := range roleList {
	// 	for _, j := range list {
	// 		cachePath := strings.Split(j.Path, "_")
	// 		if len(cachePath) > 1 {
	// 			if v.V1 == cachePath[0] && v.V2 == cachePath[1] {
	// 				havePerm = append(havePerm, j)
	// 			}

	// 		}

	// 	}
	// }

	return &havePerm, nil
}

/** 获取用户列表以及校色 --弃用*/
// func (m *PmControl) PmList(paginat *dto.ReqPaginat) ([]dto.Pm_listDto, int64, error) {
// 	var trimList []dto.Pm_listDto
// 	var errList error
// 	list, total, err := UserC.GetUserList(*paginat)
// 	if err != nil {
// 		return nil, total, err
// 	}
// 	for _, v := range list {
// 		cache, err := m.Dao.PmUserFindRole(v.User)
// 		if err != nil {
// 			errList = utils.AppendError(errList, err)
// 		}
// 		//TODO:对象赋值对象必须要简化
// 		trimList = append(trimList, dto.Pm_listDto{Role: cache, Id: v.ID, User: v.User, Gender: v.Gender, Last_Login_Ip: v.Last_Login_Ip, User_Level_Id: v.User_Level_Id, Nickname: v.Nickname, Mobile: v.Mobile, Avatar: v.Avatar, Birthday: v.Birthday, Register_Ip: v.Register_Ip, Last_Login_Time: v.Last_Login_Time})
// 	}
// 	return trimList, total, errList
// }
